import * as actionType from './constants.js';
import {reqSearchAll,reqSongUrl,reqSingerInfoRequest,reqSongDetail,reqSongLyric} from '../../../api/index'

export const changeSearchAll = (data)=>{
    // console.log('进去成功.....')
    return{
        type: actionType.GET_SEARCHALL,
        data:data
    }
}
export const changeSongUrl = (data)=>{
    // console.log('进去成功.....')
    return{
        type: actionType.GET_SONGURL,
        data:data
    }
}

export const changeSingerInfoRequest = (data)=>{
    // console.log('进去成功.....')
    return{
        type: actionType.GET_SINGERDETAIL,
        data:data
    }
}

export const changeSongDetail = (data)=>{
    // console.log('进去成功.....')
    return{
        type: actionType.GET_SONGDETAIL,
        data:data
    }
}

export const changeSongLyric = (data)=>{
    console.log('进去成功.....')
    return{
        type: actionType.GET_SONGLYRIC,
        data:data
    }
}
export const getSongLyric = (id) =>{
    // console.log(keywords,'id');
    return (dispatch) =>{
        reqSongLyric(id)
            .then((res) =>{
                // console.log(res,'key');
                dispatch(changeSongLyric(res.data))
            })
            .catch((e) =>{
                console.log(e,'error')
            })
    }
}

export const getSongDetail = (id) =>{
    // console.log(keywords,'id');
    return (dispatch) =>{
        reqSongDetail(id)
            .then((res) =>{
                // console.log(res,'key');
                dispatch(changeSongDetail(res.data))
            })
            .catch((e) =>{
                console.log(e,'error')
            })
    }
}


export const getSearchAll = (keywords) =>{
    // console.log(keywords,'id');
    return (dispatch) =>{
        reqSearchAll(keywords)
            .then((res) =>{
                // console.log(res,'key');
                dispatch(changeSearchAll(res.data))
            })
            .catch((e) =>{
                console.log(e,'error')
            })
    }
}
export const getSingerInfoRequest = (id) =>{
    // console.log(id,'--------')
    return (dispatch) =>{
        reqSingerInfoRequest(id)
            .then((res) =>{
                // console.log(res,'url');
                dispatch(changeSingerInfoRequest(res.data))
            })
            .catch((e) =>{
                console.log(e,'error')
            })
    }
}
export const getSongUrl = (id) =>{
    // console.log(id,'id');
    return (dispatch) =>{
        reqSongUrl(id)
            .then((res) =>{
                // console.log(res,'url');
                dispatch(changeSongUrl(res.data.data))
            })
            .catch((e) =>{
                console.log(e,'error')
            })
    }
}